package demo3;

class Food{

}

class Fruit extends Food{

}

class Apple extends Fruit{

}

class Banana extends Fruit{

}

class Plate<T>{
    private T data;

    public T getData(){
        return this.data;
    }

    public void setData(T data){
        this.data = data;
    }
}

public class TestDemo {

    public static void func2(Plate<? super Fruit> plate){
        plate.setData(new Apple());
        plate.setData(new Banana());
        // plate.setData(new Food());

        Fruit fruit = (Fruit) plate.getData();
    }

    public static void func(Plate<? extends Fruit> plate){
        System.out.println(plate.getData());

        Fruit apple = plate.getData();
        // plate.setData(new Apple()); // error
        // plate.setData(new Banana());// error
    }

    public static void main(String[] args) {
        Plate<Food> plate1 = new Plate<>();
        Plate<Fruit> plate2 = new Plate<>();

        func2(plate1);
        func2(plate2);
    }

    public static void main1(String[] args) {
        Plate<Apple> plate1 = new Plate<>();
        plate1.setData(new Apple());

        Plate<Banana> plate2 = new Plate<>();
        plate2.setData(new Banana());

        func(plate1);
        func(plate2);

        Plate<Food> plate3 = new Plate<>();
        // func(plate3);
    }
}
